<h1>Message box</h1>

<!-- the tabs -->
<ul class="css-tabs" id="nav">
	<li><a href="#"><b>Inbox</b></a></li>
	<li><a href="#"><b>Outbox</b></a></li>
</ul>

<!-- tab "panes" -->
<div class="css-panes" id="panes">

<div class="fbblueboxlite" style="display:block;border-top-color:#eceff6">
  <table  rules="groups" frame="below">
    <tr>
      <th style="min-width:100px"></th>
      <th style="width:100%; max-width:200px"></th>
      <th style="width:100px"></th>
      <th></th>
    </tr>
    <% count = 0; %>
    <% @messages.each do |message| %>
        <% if message.receiver == User.find_by_id(session[:user_id]).name %>
            <colgroup>
              <tr>
                <td><b><a href="<%= User.find_by_name(message.sender).role.pluralize %>/<% sender_role = User.find_by_name(message.sender).role %><% if sender_role == "student"%><%= Student.find_by_student_id(message.sender).id %><% elsif sender_role == "company" %><%= Company.find_by_company_id(message.sender).id %><% elsif sender_role == "camt" %><% end %>"><%= message.sender %></a></b></td>
                <td><a href="messages/<%= message.id %>"><%= message.subject %></a></td>
                <% if Message.find_by_receiver(message.receiver).created_at.today? %>
                <td>Today</td>
                    <% end %>
                <td><%= button_to 'Delete', message, :confirm => 'Are you sure?', :method => :delete %></td>
              </tr>
              <td colspan="4">
                <% if message.body.length > 90 %>
                    <%= message.body.slice!(0..90) %>...
                <% else %>
                    <%= message.body %>
                <% end %>
              </td>
            </colgroup>
            <% count = count + 1 %>
        <% end %>

    <% end %>
    <% if count == 0 %>
        <div style="text-align:center;">No message in your inbox</div>
    <% end %>

  </table>
</div>

<div class="fbblueboxlite" style="display:block;border-top-color:#eceff6">
  <table  rules="groups" frame="below">
    <tr>
      <th style="min-width:100px"></th>
      <th style="width:100%; max-width:200px"></th>
      <th></th>
    </tr>
    <% count = 0; %>
    <% @messages.each do |message| %>
        <% if message.sender == User.find_by_id(session[:user_id]).name %>
            <colgroup>
              <tr>
                <td><b><a href="<%= User.find_by_name(message.receiver).role.pluralize %>/<% receiver_role = User.find_by_name(message.receiver).role %><% if receiver_role == "student"%><%= Student.find_by_student_id(message.receiver).id %><% elsif receiver_role == "company" %><%= Company.find_by_company_id(message.receiver).id %><% elsif receiver_role == "camt" %><% end %>"><%= message.receiver %></a></b></td>
                <td><a href="messages/<%= message.id %>"><%= message.subject %></a></td>
                <td><%= button_to 'Delete', message, :confirm => 'Are you sure?', :method => :delete %></td>
              </tr>
              <td colspan="4">
                <% if message.body.length > 90 %>
                    <%= message.body.slice!(0..90) %>...
                <% else %>
                    <%= message.body %>
                <% end %>
              </td>
            </colgroup>
            <% count = count + 1 %>
        <% end %>
    <% end %>
    <% if count == 0 %>
        <div style="text-align:center;">No message in your outbox</div>
    <% end %>
  </table>
</div>
</div>

  <br />




<div class="fbgreyboxbuttom">
  <%= button_to 'New Message', new_message_path %>
</div>